﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Data.SqlClient;
using System.Text.RegularExpressions;

namespace TextMIS
{
    public partial class frmManEdit : Form
    {
        public frmManEdit()
        {
            InitializeComponent();
        }

        public static string userRight;
        public static string strValue;
        SqlConnection conn;
  //      SqlCommand com;
        SqlDataAdapter da;
   //     SqlDataReader dr;

        private void frmManEdit_Load(object sender, EventArgs e)
        {
            userRight = frmLogin.userRight;
            conn = new
SqlConnection(frmLogin.SQLstr);
            listView1.GridLines = true;
            listView1.FullRowSelect = true;
            listView1.View = View.Details;
            listView1.Scrollable = true;
            listView1.MultiSelect = false;
            listView1.HeaderStyle = ColumnHeaderStyle.Nonclickable;
            tcbCondition.Items.Add("注册编号");
            tcbCondition.Items.Add("登陆账号");
            tcbCondition.Items.Add("真实姓名");
            tcbCondition.Items.Add("手机号码");
            strValue = "select UserName,UserPassword,UserRight from UserInfo ";
            this.ShowInfo();

        }

        private void SetupHeaderLIST()
        {
            listView1.Columns.Add("登陆账号", 100, HorizontalAlignment.Left);
            listView1.Columns.Add("登陆密码", 120, HorizontalAlignment.Left);
            listView1.Columns.Add("用户权限", 100, HorizontalAlignment.Left);
        }

        private void ShowInfo()
        {
            try
            {
                listView1.Clear();

                da = new SqlDataAdapter(strValue, conn);

                DataTable dt = new DataTable();
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                int count = da.Fill(dt);
                conn.Close();

                SetupHeaderLIST();
                foreach (DataRow dr in dt.Rows)
                {
                    ListViewItem lvi = new ListViewItem();
                    lvi.SubItems.Clear();
                    lvi.SubItems[0].Text = dr[0].ToString();
                    lvi.SubItems.Add(dr[1].ToString());
                    lvi.SubItems.Add(dr[2].ToString());
                    listView1.Items.Add(lvi);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void tsbOK_Click(object sender, EventArgs e)
        {
            if (tcbCondition.Text == "注册编号")
            {
                if (tstValue.Text != "")
                {
                    strValue = "select UserName,UserPassword,UserRight from viewPU_tab where RegisterID='" + tstValue.Text.Trim() + "' ";
                    this.ShowInfo();
                }
                else
                { MessageBox.Show("请根据查询条件输入查询值！", "提示"); }
            }

            if (tcbCondition.Text == "登陆账号")
            {
                if (tstValue.Text != "")
                {
                    strValue = "select UserName,UserPassword,UserRight from viewPU_tab where UserName='" + tstValue.Text.Trim() + "' ";
                    this.ShowInfo();
                }
                else
                { MessageBox.Show("请根据查询条件输入查询值！", "提示"); }
            }

            if (tcbCondition.Text == "真实姓名" )
            {
                if (tstValue.Text != "")
                {
                    strValue = "select UserName,UserPassword,UserRight from viewPU_tab where Pname='" + tstValue.Text.Trim() + "' ";
                    this.ShowInfo();
                }
                else
                { MessageBox.Show("请根据查询条件输入查询值！", "提示"); }

            }

            if (tcbCondition.Text == "手机号码")
            {
                if (tstValue.Text != "")
                {
                    strValue = "select UserName,UserPassword,UserRight from viewPU_tab where Pphone='" + tstValue.Text.Trim() + "' ";
                    this.ShowInfo();
                }
                else
                { MessageBox.Show("请根据查询条件输入查询值！", "提示"); }
            }

            if (tcbCondition.Text == "")
            {
                    strValue = strValue = "select UserName,UserPassword,UserRight from UserInfo ";
                this.ShowInfo();
                MessageBox.Show("请输入相应的查询条件和查询值！","提示");
            }
        }

        private void tsbExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
